package com.yt.app.api.vo;

import com.google.common.collect.Lists;
import com.yt.app.core.model.UserContact;
import com.yt.order.api.model.Institution;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Description
 * <p>
 * </p>
 * DATE 2017/10/25.
 *
 * @author liujunshi.
 */
@ApiModel(value = "预约初始数据", description = "")
public class ToReserveVo {
    @ApiModelProperty(value = "联系人")
    private List<UserContact> userContacts;
    @ApiModelProperty(value = "订单信息")
    private ReserveOrderVo orderVo;
    @ApiModelProperty(value = "机构城市")
    private List<ToReserveCityVo> citys;
    @ApiModelProperty(value="预约ID")
    private Long reservationId;
    public List<UserContact> getUserContacts() {
        return userContacts;
    }

    public void setUserContacts(List<UserContact> userContacts) {
        this.userContacts = userContacts;
    }

    public ReserveOrderVo getOrderVo() {
        return orderVo;
    }

    public void setOrderVo(ReserveOrderVo orderVo) {
        this.orderVo = orderVo;
    }

    public Long getReservationId() {
        return reservationId;
    }

    public void setReservationId(Long reservationId) {
        this.reservationId = reservationId;
    }

    public List<ToReserveCityVo> getCitys() {
        return citys;
    }

    public void setCitys(List<ToReserveCityVo> citys) {
        this.citys = citys;
    }

    public void addInstitution(List<Institution> institutionList) {
        Map<String, ToReserveCityVo> cityMap = new HashMap<String, ToReserveCityVo>();
        for(Institution institution : institutionList) {
            ToReserveCityVo vo = cityMap.get(institution.getCity());
            if(vo == null){
                vo = new ToReserveCityVo();
                vo.setCity(institution.getCity());
                cityMap.put(institution.getCity(), vo);
            }
            vo.addInstitution(institution);
        }
        this.citys = Lists.newArrayList(cityMap.values());
    }
}
